﻿using System;
using System.Collections.Generic;
using System.Linq;
using IterationLife.ContentResources.Models;
using IterationLife.Extensions.Dtos;
using IterationLife.Extensions.Helpers;
using Util;

namespace IterationLife.Mobile.AppServices.Dtos.Common
{
    /// <summary>
    /// 内容资源列表[输出]
    /// </summary>
    public class ContentResourceListOutPut
    {
        /// <summary>
        /// 初始化内容资源列表[输出]
        /// </summary>
        public ContentResourceListOutPut()
        {
            Tags = new List<string>();
        }

        /// <summary>
        /// 编号
        /// </summary>
        public Guid Id { get; set; }

        /// <summary>
        /// 类型
        /// </summary>
        public int? Type { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 标签
        /// </summary>
        public List<string> Tags { get; set; }

        /// <summary>
        /// 单封面图
        /// </summary>
        public string SingleBanner { get; set; }

        /// <summary>
        /// 多封面图
        /// </summary>
        public List<string> MultiBanners { get; set; }

        /// <summary>
        /// 封面类型
        /// </summary>
        public int? BannerType { get; set; }

        /// <summary>
        /// 评论数
        /// </summary>
        public long CommentCount { get; set; }

        /// <summary>
        /// 时间
        /// </summary>
        public string Time { get; set; }
    }

    /// <summary>
    /// 内容资源列表[输出]扩展
    /// </summary>
    public static class ContentResourceListOutPutExtension
    {
        /// <summary>
        /// 转换为内容资源列表[输出]
        /// </summary>
        /// <param name="entity">内容资源</param>
        /// <param name="commentCount">评论数</param>
        public static ContentResourceListOutPut ToNewsListOutPut(this ContentResource entity, long commentCount)
        {
            return new ContentResourceListOutPut
            {
                Id = entity.Id,
                Type = entity.Type.Value(),
                Title = entity.Title,
                Tags = Util.Helpers.Convert.ToList<string>(entity.Tags),
                SingleBanner = entity.SingleBanner.ImageSlim().Address,
                MultiBanners = entity.MultiBanners.Select(t => t.ImageSlim().Address).ToList(),
                BannerType = entity.BannerType.Value(),
                CommentCount = commentCount,
                Time = TimeHelper.IntervalDescription(entity.PublicationTime.SafeValue(), DateTime.Now)
            };
        }
    }
}
